package com.jiyun.controller;

import com.jiyun.pojo.ThContract;
import common.models.dtos.ContractDto;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jiyun.service.IThContractService;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  合同表
 * </p>
 *
 * @author usian
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/contract")
@Api(tags = "接口")
@CrossOrigin
public class ThContractController{

    @Autowired
    private IThContractService thContractService;

    /**
     * 关键字进行查询
     * @param dto
     * @return
     */
    @PostMapping("/findContract")
    public List<ThContract> findContract(@RequestBody ContractDto dto){
        List<ThContract> keyList = thContractService.findKeyList(dto);

//        if (CollectionUtils.isEmpty(list)){
//            throw new RuntimeException("查询数据为空");
//        }
        return keyList;
    }

    /**
     * 添加合同
     * @param thContract
     * @return
     */
    @PostMapping("/add")
    public String add(@RequestBody ThContract thContract){
        if (thContract==null){
            throw new RuntimeException("参数为空");
        }
        boolean save = thContractService.save(thContract);
        if (save){
            return "新增合同成功";
        }else {
            return "新增合同失败";
        }
    }

}
